home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
progjour
/
1991
/
01
/
malloc.asm
< prev
next >
Wrap
Assembly Source File
|
1990-11-01
|
1KB
|
93 lines
title malloc
include asm.inc
public calloc
public free
public malloc
.const
ertx_malloc_range db 'malloc out of range',0
.code
extn ms_dos_strerror,set_strerror
;; calloc
;
; entry CX requested byte count (1..FFF0)
; exit ES:DI storage pointer
; AX actual byte count
; Cf if no storage
;
calloc proc
call malloc ; allocate storage
jc cal1
pushm ax,cx,di ; zero storage
mov cx,ax
movx ax,0
shr cx,1
rep stosw
popm di,cx,ax
cal1: ret
calloc endp
;; free
;
; entry ES:DI storage pointer (OK if NULL)
; exit ES:DI NULL
; Cf if bad pointer
; uses AX
;
free proc
mov ax,es
or ax,di
jz fee1 ;\ if NULL pointer - ignore call
mov ah,49h
call ms_dos_strerror
mov di,NULL_POINTER ; return NULL (don't modify flags)
mov es,di
fee1: ret
free endp
;; malloc
;
; entry CX requested byte count (1..FFF0)
; exit ES:DI storage pointer
; AX actual byte count
; Cf if no storage
;
malloc proc
jcxz mal2 ; if byte count out of range
mov ax,cx
add ax,15
jc mal2 ; if byte count out of range
and al,0F0h
pushm ax,bx ; convert byte count to paragraph cnt
shr ax,1
shr ax,1
shr ax,1
shr ax,1
mov bx,ax
mov ah,48h ; request memory from dos
call ms_dos_strerror
jc mal1 ; if not enough memory
mov es,ax
movx di,NULL_POINTER
mal1: popm bx,ax
ret
mal2: lea ax,ertx_malloc_range
jmp set_strerror
malloc endp
end